package testDay;

import java.util.HashMap;
import java.util.Map;

public class day2_1 {
    public int singleNumber(int[] nums) {
        /*
         * 1.创建一个HashMap用来记录数组中数字重复的次数
         * 2.循环数组将数组中数值放入hashmap，若已存在value加1，否则value赋值1
         * 3.遍历hashmap找出value为1的key值返回
         */
        HashMap<String, Integer> hashMap = new HashMap();
        int res = 0;

        for (int i = 0; i < nums.length; i++) {
            String key = Integer.toString(nums[i]);
            int value = 1;
            if (hashMap.containsKey(key)) {
                hashMap.put(key, hashMap.get(key) + 1);
            } else {
                hashMap.put(key, value);
            }
        }
        System.out.println(hashMap.get("2"));
        for (String key : hashMap.keySet()) {
            if (hashMap.get(key) == 1) {
                res = Integer.valueOf(key);
            }
        }
        return res;
    }
}
